﻿using System;
using System.Collections.Generic;
using System.Text;
using IBLL.Controller;
using IBLL.View;
using AppToolKit.Core.Context.Spring;

namespace BLL.Controller
{
    public class ControllerFactory
    {
        [AutoWiring]
        public ContextAware ContextHanlder { get; set; }
        //[AutoWiring]
        //public FormBuilder FormBuilderHandler { get; set; }

        public IFormController GetController<TController, TView>()
            where TController : IFormController
            where TView: IViewForm
        {
            IViewForm view = ContextHanlder.Create<TView>();
            IFormController controller = ContextHanlder.Create<TController>();
            controller.View = view;
            return controller;
        }
        public IFormController GetController<TController, TView>(object key)
            where TController : IFormController
            where TView : IViewForm
        {
            IViewForm view = ContextHanlder.Create<TView>();
            IFormController controller = ContextHanlder.Create<TController>();
            controller.View = view;
            controller.PrimaryKey = key;
            return controller;
        }
    }
}
